<!-- 进出登记 -->
<template>
	<view>
		<!-- <block v-if="(!!bookingCarDetail.carcode)&&(bookingCarDetail.carcode.length>0)"> -->
		<BookingCarDetail ref="bookingCarDetail" :item="bookingCarDetail"></BookingCarDetail>
		<RecordInoutPart1 ref="recordInoutPart1" :item="cardDetail"></RecordInoutPart1>
		<!-- <view class="btn-box">
			<button class="ml10 mr10 btn1" type="warn" size="mini" @click="doSubmit()"> 确定 </button>
			<button class="ml10 mr10 btn2" type="warn" size="mini" plain="true" @click="doSubmit(2)"> 取消 </button>
		</view> -->
		<!-- </block> -->
		<!-- <block v-else>
			<view class="nodata-box">
				<view class="nodata-img">
					<image src="/static/img/icon/icon-no-data.png" class="img" mode="aspectFill"></image>
				</view>
				<view class="nodata-txt">
					没有预约信息
				</view>
			</view>

		</block> -->
	</view>

</template>

<script>
	import RecordInoutPart1 from "@/pages/record/components/record-inout/record-inout-part1.vue"
	import BookingCarDetail from "@/pages/booking/components/booking-car/booking-car-detail.vue"
	import {
		Platform,
		Storage_Key,
		CarSetting
	} from "@/static/config.js"
	import indexHandler from '@/pages/index/index.js'
	export default {
		components: {
			RecordInoutPart1,
			BookingCarDetail
		},
		computed: {
			webUserInfo() {
				return this.$storage.get(Storage_Key.web_user_info, true);
			},
		},
		data() {
			return {
				cardCode: "", // 定位卡编号
				bookingCarDetail: {}, // 车辆预约数据
			}
		},
		onLoad(options) {
			if (options && options.item) {
				// 解析 ZY 二维码数据[平台标记，预约ID，预约车牌号，预约车辆类型]
				// let bookingCarDetailTemp = options.item.split(',');
				// this.bookingCarDetail = {
				// 	id: bookingCarDetailTemp[1]
				// };
				this.bookingCarDetail = JSON.parse(decodeURIComponent(options.item));
				// this.getStpBookingById();
			}
			this.setListening(); // 设置监听

		},
		// 页面隐藏
		onHide() {},
		// 页面卸载
		onUnload() {},
		methods: {
			// 设置监听
			setListening() {
				let _self = this;
				uni.$off('recordIn'); //只提供事件，不提供回调函数，则移除该事件所有的监听器
				uni.$on('recordIn', function(data) {
					if (data.key) {
						// >>> 定位卡信息
						// _self.cardCode = JSON.parse(decodeURIComponent(data.msg));
						_self.cardCode = data.msg;
						// >>> 定位卡与车辆绑定
						_self.saveOrUpdate();
					}
				})
			},
			// 提交进入园区登记信息
			saveOrUpdate() {
				let formData = {
					bookingid: this.bookingCarDetail.id, // 预约ID
					carcode: this.bookingCarDetail.carcode,
					cardcode: this.cardCode,
					status: CarSetting.recordinout.in, // 来源为监听recordIn，即进入
					creatorid: this.webUserInfo.user.userId,
					creator: this.webUserInfo.user.userName
				}
				indexHandler.saveOrUpdate(formData);
			},

		}
	}
</script>

<style lang="scss" scoped>
	.nodata-box {
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		height: 90vh;
		width: 100vw;

		.nodata-img {
			.img {
				width: 100px;
				height: 100px;
			}
		}
	}

	.btn-box {
		background: #FFFFFF;
		margin: 15px 0;
		display: flex;
		justify-content: space-around;

		.btn1 {
			width: 90%;
			background-color: #1296db;
		}

		.btn2 {
			width: 90%;
			color: #1296db;
			border: 1px solid #1296db;
		}
	}
</style>
